<?php
require_once('kernel.inc');

if($AUTH->logedstatus === true && $AUTH->permission == 'system')
{
   $GB = new kernel('gb');
   $GB->SetParams('mode=d-');

   if(isset($_REQUEST['dele']))
   {
      $GB->Delete($_REQUEST['dele']);
      SmartyPaginate::reset($_SYS['meccano']['pid']);
      SmartyPaginate::setLimit($MECCANO->system['items'], $_SYS['meccano']['pid']);
      SmartyPaginate::setPageLimit($MECCANO->system['pages'], $_SYS['meccano']['pid']);
   }

   if($action == 1 && $id != false)
   {
      $SMARTY->assign_by_ref('id', $id);
      $SMARTY->display('admin.editgb.tpl.html');
   } else
   {
      if($submit == true && $id != false && isset($_REQUEST['comment']))
      {
         $comment = prepare_str($_REQUEST['comment']);
         $sql_datas[0] = $comment;
         $sql_datas[1] = $id;
         $DB->DB_QueryBuilder("UPDATE meccano_gb SET comment = '%s' WHERE id = %i", $sql_datas);
         $DB->DB_Query();
      }

      $vars = $GB->Get();
      if($vars)
      {
         SmartyPaginate::setTotal(count($vars), $_SYS['meccano']['pid']);
         SmartyPaginate::setUrl($_SERVER['PHP_SELF'], $_SYS['meccano']['pid']);
         $SMARTY->assign('vars', array_slice($vars, SmartyPaginate::getCurrentIndex($_SYS['meccano']['pid']), SmartyPaginate::getLimit($_SYS['meccano']['pid'])));
         SmartyPaginate::assign($SMARTY, 'paginate', $_SYS['meccano']['pid']);
      } else
      {
         $SMARTY->assign('vars', false);
      }
      $SMARTY->display('admin.gb.tpl.html');
   }
} else
{
   echo $AUTH->frame_redirector();
}

/**
 * CREATE TABLE meccano_gb (
 * id int(10) unsigned auto_increment,
 * dat timestamp NOT NULL default CURRENT_TIMESTAMP,
 * name varchar(100) NOT NULL,
 * city varchar(50) default NULL,
 * site varchar(100) default NULL,
 * email varchar(100) default NULL,
 * content text NOT NULL,
 * comment text,
 * ip int(10) NOT NULL,
 * PRIMARY KEY(id)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
 */
?>